package com.atguigu.jdkOnePointEight;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
/**
 * @author Guo 2022/11/18 17:37:06
 */

public class LocalDateTest {
    public static void main(String[] args) {
        String data1="2011-08-19";
        String data2="2017-06-14";
        LocalDate startDate = LocalDate.parse(data1);
        LocalDate endDate = LocalDate.parse(data2);
        LocalDate startDateOfYear = startDate.with(TemporalAdjusters.firstDayOfYear());
        LocalDate endDateOfYear = endDate.with(TemporalAdjusters.firstDayOfYear());
        long day1 = ChronoUnit.DAYS.between(startDate, endDate);
        long year=ChronoUnit.YEARS.between(startDate, endDate);
        long day2=ChronoUnit.DAYS.between(startDateOfYear, endDateOfYear);
        if (day2>day1){
            endDateOfYear = endDateOfYear.minusYears(1);
            day2=ChronoUnit.DAYS.between(startDateOfYear, endDateOfYear);
        }
        System.out.println("相差"+year+"年"+(day1-day2)+"天");
    }
}
